package com.abel.demo.common;

/**
 * Author: Abel.lin
 * Date: Created in 2018/7/11 17:26
 * Company: Abel.Studio
 * Copyright: Copyright (c) 2017
 * Description:
 */
public class RespResult {
    private int code;
    private String msg;
    private Object data;

    public RespResult ok(){
        this.code = RstCode.SUCCESS.getCode();
        this.msg = "success";
        return this;
    }

    public RespResult ok(Object data){
        this.code = RstCode.SUCCESS.getCode();
        this.msg = "success";
        this.data = data;
        return this;
    }

    public RespResult ok(String msg, Object data){
        this.code = RstCode.SUCCESS.getCode();
        this.msg = msg;
        this.data = data;
        return this;
    }

    public RespResult fail(){
        this.code = RstCode.FAIL.getCode();
        this.msg = "fail";
        return this;
    }
    public RespResult fail(String msg){
        this.code = RstCode.FAIL.getCode();
        this.msg = msg;
        return this;
    }
    public RespResult fail(int code, String msg){
        this.code = code;
        this.msg = msg;
        return this;
    }

    public static enum RstCode{
        SUCCESS(200),   //成功
        PARAM_ERROR(400),      //请求参数错误
        UNAUTHORIZED(401), //未认证
        NOT_FOUND(404),    //请求不存在
        SERVER_ERROR(500), //服务错误
        FAIL(900);        //操作失败

        private int code;
        RstCode(int code){
            this.code = code;
        }

        public int getCode(){
            return code;
        }

    }
}
